#ifndef _DICTIONARY_H_
#define _DICTIONARY_H_
#include "KeyRecommander.h"
#include <vector>
#include <map>
#include <set>

using std::vector;
using std::map;
using std::set;
using std::pair;

class Dictionary{
private:
    vector<pair<string,int>> _dict;
    map<string,set<int>> _index;
    
    static Dictionary *_ptr;
public:
    static Dictionary *getInstance();
    static void destroy();

    void init (const string & dictEn,const string &dictCn,const string &indexEn,const string &indexCn);
    string doQuery(string word);
    
    map<string,set<int>> &getIndex();
    vector<pair<string,int>> &getDict();
private:
    Dictionary(){}
    ~Dictionary(){}

    size_t readDict(const string path);
    void readIndex(const string path,size_t offset);
public:
    //最小距离算法
    size_t nBytesCode(const char ch);
    size_t length(const string &str);
    int triple_min(const int &a, const int &b, const int &c);
    int editDistance(const string & lhs, const string &rhs);
};

//RAII


#endif